package com.will.seed.websocket;

import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;

/**
 * Created by Administrator on 2018/8/21.
 */
@Slf4j
public class SyncReceiver implements MessageListener {

    private final String id;

    public SyncReceiver(String id){
        this.id = id;
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        log.info(message.toString());
        if(ChannelManager.getInstance().getChannelCtxMap().containsKey(id)){
            ChannelManager.getInstance()
                    .getChannelCtxMap().get(id)
                    .writeAndFlush(new TextWebSocketFrame("server back msg:" + message.toString()));
        }
    }
}
